import math

s = input()
n = s.split()
x = " "
for i in n:

  if i == "one":
    x += "1"
  if i == "two":
    x += "2"
  if i == "three":
    x += "3"
  if i == "four":
    x += "4"
  if i == "five":
    x += "5"
  if i == "six":
    x += "6"
  if i == "seven":
    x += "7"
  if i == "eight":
    x += "8"
  if i == "nine":
    x += "9"
  if i == "zero":
    x += "0"


def has_digits(input_string):
  return any(char.isdigit() for char in input_string)


def is_prime(num):
  if num <= 1:
    return False
  for i in range(2, int(math.sqrt(num)) + 1):
    if num % i == 0:
      return False
  return True


def find_nearest_prime(num):
  lower = num - 1
  upper = num + 1

  while not is_prime(lower) and not is_prime(upper):
    lower -= 1
    upper += 1

  if abs(lower - num) <= abs(upper - num):
    return lower
  else:
    return upper


if has_digits(n):
  print("Wrong input")
else:
  number = int(x)

  nearest_prime = find_nearest_prime(number)
  print(nearest_prime)
